using System;
using System.Collections.Generic;

namespace LannyPractiseCode.Shu
{
    public class BinaryTree
    {
        public MyHeroNode root { set; get; }

        //前序遍历
        public void PreOrder()
        {
            if (this.root != null)
                this.root.PreOrder();
            else
                System.Console.WriteLine("Kong..");
        }

        //中序遍历
        public void InFixOrder()
        {
            if (root != null)
                this.root.InFixOrder();
            else
                System.Console.WriteLine("Kong..");
        }
        //后序遍历
        public void Postrder()
        {
            if (root != null)
                this.root.PostOrder();
            else
                System.Console.WriteLine("Kong..");
        }

        public MyHeroNode PreOrderSearch(int No)
        {
            if (root != null)
                return root.PreOrderSearch(No);
            else
                return null;
        }

        public MyHeroNode InFixOrderSearch(int no)
        {
            if (root != null)
                return root.InFixOrderSearch(no);
            else
                return null;
        }

        public MyHeroNode PostOrderSerach(int no)
        {
            if (root != null)
                return root.PostOrderSerach(no);
            else
                return null;
        }

        //删除节点
        public void DeleNode(int no)
        {
            if(root !=null)
            {
                if(this.root.Id==no)
                    root=null;
                else
                    root.DeleNode(no);
            }
            else
            {
                System.Console.WriteLine("空树，不能删除！~");
            }
        }
    }
}